﻿using NCS.IConnect.Core.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace NCS.IConnect.Core.WebApi.Description
{
    /// <summary>
    /// This attribute which is annotated on action method to provide response description information.
    /// </summary>
    [AttributeUsage( AttributeTargets.Method, AllowMultiple =true)]
    public class ResponseAttribute: Attribute
    {
        /// <summary>
        /// Gets the condition.
        /// </summary>
        /// <value>The condition.</value>
        public ConditionInfo Condition { get; internal set; }

        /// <summary>
        /// Gets the status code of the response.
        /// </summary>
        /// <value>The status code of response.</value>
        public HttpStatusCode StatusCode { get; internal set; }

        /// <summary>
        /// Gets the data type of the response content.
        /// </summary>
        /// <value>The data type of the response content.</value>
        public Type ContentDataType { get; private set; }

        /// <summary>
        /// Gets the error code for error response.
        /// </summary>
        /// <value>The error code for error response.</value>
        public string ErrorCode { get; internal set; }

        internal ResponseAttribute()
        { }

        private ResponseAttribute(HttpStatusCode statusCode, string conditionDescription, string conditionCode)
        {
            Guard.ArgumentNotNullOrEmpty(conditionDescription, "conditionDescription");
            this.Condition = new ConditionInfo(conditionCode, conditionDescription);
            this.StatusCode = statusCode;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ResponseAttribute" /> class.
        /// </summary>
        /// <param name="statusCode">The status code of response.</param>
        /// <param name="conditionCode">The condition code.</param>
        /// <param name="conditionDescription">The condition description.</param>
        /// <param name="contentDataType">The data type of the response content.</param>
        public ResponseAttribute(HttpStatusCode statusCode,  string conditionDescription, Type contentDataType, string conditionCode = "")
            : this(statusCode, conditionDescription, conditionCode)
        {
            Guard.ArgumentNotNull(contentDataType, "contentDataType");
            this.ContentDataType = contentDataType;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ResponseAttribute" /> class.
        /// </summary>
        /// <param name="statusCode">The status code of response.</param>
        /// <param name="conditionCode">The condition code.</param>
        /// <param name="conditionDescription">The condition description.</param>
        /// <param name="errorCode">The error code for error response.</param>
        public ResponseAttribute(HttpStatusCode statusCode, string conditionDescription, string errorCode, string conditionCode = "")
            : this(statusCode, conditionDescription, conditionCode)
        {
            this.ErrorCode = errorCode;
        }
    }
}